package com.monco.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.monco.entity.UserScore;
import com.monco.mapper.UserScoreMapper;
import com.monco.service.IUserScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author com/monco
 * @since 2020-03-11
 */
@Service
public class UserScoreServiceImpl extends ServiceImpl<UserScoreMapper, UserScore> implements IUserScoreService {

    @Resource
    private UserScoreMapper userScoreMapper;

    @Override
    public List<UserScore> getUserScoreList(UserScore userScore) {
        return userScoreMapper.selectList(getWrapper(userScore));
    }

    @Override
    public IPage<UserScore> getUserScorePage(IPage<UserScore> page, UserScore userScore) {
        return userScoreMapper.selectPage(page, getWrapper(userScore));
    }

    private QueryWrapper<UserScore> getWrapper(UserScore userScore) {
        QueryWrapper<UserScore> queryWrapper = new QueryWrapper<>();
        if (userScore.getUserId() != null) {
            queryWrapper.eq("user_id", userScore.getUserId());
        }
        return queryWrapper;
    }
}
